Cellpose test (win)
#5_image_analysis
準備
Miniconda + conda-forgeによる環境構築 (2024.06.26)
Sample code
code:jupyter notebook
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from cellpose import models, io, plot, core
from cellpose.io import imread
import torch
code:jupyter notebook
##画像読み込み、Stacked tiff images
fname = 'Merge.tif'
imgs = io.imread(fname)
for img in imgs:
plt.figure(figsize=(2,2))
plt.imshow(img)
plt.axis('off')
plt.show()
code:jupyter notebook
## GPU使えるか確認
use_GPU = core.use_gpu()
print('>>> GPU activated? %d'%use_GPU)
code:jupyter notebook
%%time
## CPUで実行
model = models.Cellpose(gpu=False, model_type="cyto3")
chan = 0,0
masks,flows = [],[]
for i,img in enumerate(imgs):
mask, flow, style, diam = model.eval(img, diameter=30,channels=chan)
masks.append(mask)
flows.append(flow)
io.save_to_png(img, mask, flow, 'mask/'+str(i)+'.png')
code:jupyter notebook
%%time
## GPUで実行
model = models.Cellpose(gpu=use_GPU, model_type='cyto3')
chan = 0,0
masks,flows = [],[]
for i,img in enumerate(imgs):
mask, flow, style, diam = model.eval(img, diameter=30,channels=chan)
masks.append(mask)
flows.append(flow)
io.save_to_png(img, mask, flow, 'mask/'+str(i)+'.png')
code:jupyter notebook
## 計算結果を確認
for img, mask,flow in zip(imgs,masks,flows):
fig = plt.figure(figsize=(12,5))
plot.show_segmentation(fig, img, mask, flow0, channels=chan)
plt.tight_layout()
plt.show()
Apple Silicon Macの場合
CellposeをM1 Mac GPUで動かす 参照
Privateから転載
cellPose使い方
GitHub
Paper
Youtube
Web serverでの使い方
http://www.cellpose.org/
JPEGとかの画像をアップロードするだけ。お試し。
Jupyter notebookでの使い方
Anacondaが入っていたら、Prompt上で
pip install cellpose
G suite 共有ドライブ> Lab Protocol> Programming> jupyter notebook archivesにサンプルを入れています
https://drive.google.com/drive/folders/1Mx8Gl-ZOVCWt9Itr7K1pFjcRiOC2ffkV?usp=sharing
Google colabでGPUを使ってみた。結構速い
https://colab.research.google.com/drive/14-5tu5jAY5pxcYth4qgJ2WUx8oMymeN1?usp=sharing
Remarks
https://cellpose.readthedocs.io/en/latest/notebook.html
created by y-goto.icon
2024.07.01